package adapter.group_management;

/**
 * Created by Dong Le on 5/15/2015.
 */
import com.trek2000.android.enterprise.Enterprise;
import com.trek2000.android.enterprise.R;
import com.viewpagerindicator.IconPagerAdapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentStatePagerAdapter;
import android.util.Log;

import controller.group_management.GroupManagementAsync;
import controller.group_management.MemberTabInGroupFeedFragmentAsync;
import controller.group_management.PhotoAndVDOTabInGroupFeedFragmentAsync;
import controller.group_management.SettingTabInGroupFeedFragmentAsync;
import ui.fragment.group_management.MemberTabInGroupFeedFragment;
import ui.fragment.group_management.PhotoAndVDOTabInGroupFeedFragment;
import ui.fragment.group_management.SettingTabInGroupFeedFragment;

public class GroupFeedFragmentPagerAdapter extends FragmentStatePagerAdapter implements IconPagerAdapter{
    /**
     * The others session
     */
    private Context mContext;
    public GroupFeedFragmentPagerAdapter(Context context, FragmentManager fm) {
        super(fm);
        mContext = context;
        // TODO Auto-generated constructor stub
    }

    @Override
    public int getIconResId(int index) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public Fragment getItem(int position)
    {
        // TODO Auto-generated method stub
        Fragment fragment = null;
        switch(position){
            case 0:
                Log.i("", "getItem 0: " + position);
                fragment = new PhotoAndVDOTabInGroupFeedFragment();
                break;
            case 1:
                Log.i("", "getItem 1: " + position);
                fragment = new MemberTabInGroupFeedFragment();
                break;
            case 2:
                Log.i("", "getItem 2: " + position);
                fragment = new SettingTabInGroupFeedFragment();
                break;
        }
        return fragment;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 3;
    }

    @Override
    public CharSequence getPageTitle(int position){
        String title = "";
        switch(position){
            case 0:
//                title = mContext.getString(R.string.photo_and_vdo) + "(" +
//                        String.valueOf(GroupManagementAsync.mAlGroupManagement.get(
//                                Enterprise.groupManagement.getPositionOfGroupManagementItem()
//                        ).getNumberOfShots()) + ")";
                if (SettingTabInGroupFeedFragmentAsync.mAlSettingTabInGroupFeed.size() > 0 ) {
                    title = mContext.getString(R.string.photo_and_vdo) + "(" +
                            String.valueOf(
                                    SettingTabInGroupFeedFragmentAsync.mAlSettingTabInGroupFeed.
                                            get(0).getNumberOfShots())
                            + ")";
                } else {
                    title =  mContext.getString(R.string.photo_and_vdo);
                }
                break;
            case 1:
                if (SettingTabInGroupFeedFragmentAsync.mAlSettingTabInGroupFeed.size() > 0 ) {
                    title = mContext.getString(R.string.member) + "(" +
                            String.valueOf(
                                    SettingTabInGroupFeedFragmentAsync.mAlSettingTabInGroupFeed.
                                            get(0).getNumberOfUsers()) +
                            ")";
                } else {
                    title = mContext.getString(R.string.member);
                }
                break;
            case 2:
                title = mContext.getString(R.string.setting);
                break;
        }
        return title;
    }
}
